package com.binyouwei.designpatterns.behavior.iterator;

/**
 * @author 宾有为
 * Created on 2024/7/15 19:02
 * Social homepage: https://blog.csdn.net/baidu_41616022
 * @desc
 **/
public class IteratorConcreteIterator implements Iterator {
    private IteratorConcreteCollection collection;
    private int position = 0;

    public IteratorConcreteIterator(IteratorConcreteCollection collection) {
        this.collection = collection;
    }

    @Override
    public boolean hasNext() {
        return position < collection.size();
    }

    @Override
    public Object next() {
        if (this.hasNext()) {
            Object item = collection.getItem(position);
            position++;
            return item;
        }
        return null;
    }
}
